package edu.thu.studio.ormdesigner.editor.command;

import org.eclipse.draw2d.geometry.Rectangle;

import edu.thu.studio.ormdesigner.common.AbstractCommand;
import edu.thu.studio.ormdesigner.model.diagram.Diagram;
import edu.thu.studio.ormdesigner.model.diagram.node.Node;

public class MoveNodeCommand extends AbstractCommand {
    
    protected int x;
    
    protected int oldX;
    
    protected int y;
    
    protected int oldY;
    
    protected int width;
    
    protected int oldWidth;
    
    protected int height;
    
    protected int oldHeight;
    
    private Node element;
    
    protected Diagram diagram;
    
    @SuppressWarnings("unused")
    private Rectangle bounds;
    
    public MoveNodeCommand(Diagram diagram, Rectangle bounds, int x, int y, int width, int height, Node element) {
        
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        
        this.element = element;
        this.oldX = element.getX();
        this.oldY = element.getY();
        this.oldWidth = element.getWidth();
        this.oldHeight = element.getHeight();
        
        this.bounds = bounds;
        this.diagram = diagram;
    }
    
    @Override
    protected void doExecute() {
        
        this.element.setRectangle(x, y, width, height);
        this.element.refreshVisuals();
    }
    
    @Override
    protected void doUndo() {
        this.element.setRectangle(oldX, oldY, oldWidth, oldHeight);
        this.element.refreshVisuals();
    }
}
